package com.example.jdk8;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TestOrder {
    public static void main(String[] args) {
        int firstNo = -1;
        int secondNo = -1;
        int thirdNo = -1;

        List<Map<String, Object>> priceList = initPriceList();
        System.out.println("排序前：" + priceList);
        for (int i = 0; i < priceList.size(); i++) {
            if (priceList.get(i).get("priceMode").equals("MIXED")) {
                firstNo = i;
                continue;
            }
            if (priceList.get(i).get("priceMode").equals("POINT")) {
                secondNo = i;
                continue;
            }
            if (priceList.get(i).get("priceMode").equals("CASH")) {
                thirdNo = i;
            }
        }

        List<Map<String, Object>> resultList = new ArrayList<>();
        if (firstNo != -1) {
            resultList.add(priceList.get(firstNo));
        }
        if (secondNo != -1) {
            resultList.add(priceList.get(secondNo));
        }
        if (thirdNo != -1) {
            resultList.add(priceList.get(thirdNo));
        }
        System.out.println("排序后：" + resultList);
    }

    /**
     * 初始化数据
     *
     * @return List<Map<String, Object>>
     */
    private static List<Map<String, Object>> initPriceList() {
        List<Map<String, Object>> list = new ArrayList<>();
        Map<String, Object> map = new HashMap<>();
        // 现金
        map.put("priceMode", "CASH");
        map.put("pricePoint", 0);
        map.put("priceCash", 1.0);
        list.add(map);
        // 积分
        map = new HashMap<>();
        map.put("priceMode", "POINT");
        map.put("pricePoint", 1);
        map.put("priceCash", 0.0);
        list.add(map);
        // 混合
        map = new HashMap<>();
        map.put("priceMode", "MIXED");
        map.put("pricePoint", 11);
        map.put("priceCash", 1.1);
        list.add(map);
        return list;
    }
}
